package com.gljx.web.service.impl;

import com.gljx.web.Entity.SubjectOneResultentry;
import com.gljx.web.Entity.User;
import com.gljx.web.dao.SubjectOneResultentryMapper;
import com.gljx.web.service.CustomLogService;
import com.gljx.web.service.SubjectOneResultentryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SubjectOneResultentryServiceImpl implements SubjectOneResultentryService {
	@Autowired
	private SubjectOneResultentryMapper subjecOneResultentryMapper;

	@Autowired
	private CustomLogService customLogService;

	@Override
	public int deleteSubjectOneResultentryByParentid(String parentid,User user,String fbizdate,String fnumber) {
		// TODO Auto-generated method stub
		if(user != null){
			//根据父类id查找子类信息
			List<SubjectOneResultentry> subjectOneResultentrys = subjecOneResultentryMapper.selSubjectOneResultentryByParentId(parentid,null);
			for (int i = 0; i < subjectOneResultentrys.size(); i++) {
				//添加学员的服务日志
				customLogService.addLog("考试管理",  "删除了学员:"+subjectOneResultentrys.get(i).getCfstudentno()+subjectOneResultentrys.get(i).getStudentName()+
						",科目一考试结果登记!申请车型:"+subjectOneResultentrys.get(i).getCfsqzjcx()+",考试日期:"+fbizdate+"单据编号:"+fnumber, subjectOneResultentrys.get(i).getCfstudentid(), user.getFid());
			}
		}
		return subjecOneResultentryMapper.deleteByParentId(parentid);
	}

	@Override
	public int addSubjectOneResult(SubjectOneResultentry subjectOneResultentry) {
		// TODO Auto-generated method stub
		return subjecOneResultentryMapper.insertSelective(subjectOneResultentry);
	}

	@Override
	public List<SubjectOneResultentry> selSubjectOneResultentryByParentId(String parentid, String studentName) {
		// TODO Auto-generated method stub

		return subjecOneResultentryMapper.selSubjectOneResultentryByParentId(parentid, studentName);
	}

	@Override
	public List<SubjectOneResultentry> selSubjectOneResultentryByParentIdWithcfexmaresult(String parentid, String studentName, String cfexmaresult) {
		return subjecOneResultentryMapper.selSubjectOneResultentryByParentIdWithcfexmaresult(parentid,studentName,cfexmaresult);
	}

}
